//
//  HWDataRequest.h
//  MinisoEshop
//
//  Created by 李含文 on 2020/7/29.
//  Copyright © 2020 ＾淡~忘￡°C. All rights reserved.
//

#import <Foundation/Foundation.h>

#define HW_BASE_URL @"http://172.27.2.46:8180/minisoAppService/"

/// 是否开启限制 用于测试 最好不要开 需要调用代码时配合 不然会出现异常
static BOOL HWDataManage_isOpenLimit = NO;

typedef enum : NSUInteger {
    HWRequestTypeGet = 0, // get请求
    HWRequestTypePost,    // post请求
} HWRequestType;

NS_ASSUME_NONNULL_BEGIN
@interface HWDataRequestModel : NSObject
//MARK: - 根据后台返回数据结构设定
@property (nonatomic, assign) NSInteger code;

@property (nonatomic, strong) id data;

@property (nonatomic, copy) NSString *message;

@property (nonatomic, assign) BOOL success;

//MARK: - 记录请求信息
/// 网络请求URL
@property (nonatomic, copy) NSString *url;
/// 请求头
@property (nullable, copy) NSDictionary<NSString *, NSString *> *allHTTPHeaderFields;
/// 请求参数
@property (nonatomic, copy) NSString *HTTPBody;
@end

@interface HWDataRequest : NSObject

@property (nonatomic, copy) NSString *url;
/** 请求参数  */
@property(nonatomic, strong) NSMutableDictionary *params;
/** 请求头 */
@property(nonatomic, strong) NSMutableDictionary *header;
/// 是否限制 默认:见类顶部 HWDataManage_isOpenLimit
@property (nonatomic, assign) BOOL isRestrict;
/// 请求方式
@property (nonatomic, assign, readonly) HWRequestType method;
/// 设置默认请求头 每次都携带
+ (void)setDefaultHeader:(NSDictionary *)header;
/// 取消之前的所有请求
+ (void)cancelAllRequest;
/// 根据URL取消之前的请求
+ (void)cancelRequestWithURL:(NSString *)url;

+ (void)postWithConfig:(void(^)(HWDataRequest *request))config
               success:(void(^)(HWDataRequestModel *requestModel))success
               failure:(void(^)(NSString *error))failure;

+ (void)gettWithConfig:(void(^)(HWDataRequest *request))config
               success:(void(^)(HWDataRequestModel *requestModel))success
               failure:(void(^)(NSString *error))failure;

@end



NS_ASSUME_NONNULL_END
